package enumerated;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;

import static net.mindview.util.Print.*;

/**
 * @author 杨宇
 * @version 1.0 2017/1/17.
 */
public enum E05_VowelsAndConsonants {

    VOWEL('a', 'e', 'i', 'o', 'u') {
        @Override
        public String toString() {
            return "vowel";
        }
    },
    SOMETIMES_A_VOWEL('y', 'w') {
        @Override
        public String toString() {
            return "Sometimes a vowel";
        }
    },
    CONSONANT {
        @Override
        public String toString() {
            return "consonant";
        }
    };

    private Set<Character> chars = new HashSet<>();

    E05_VowelsAndConsonants(Character... chs) {
        if (chs != null) {
            this.chars.addAll(Arrays.asList(chs));
        }
    }

    public static E05_VowelsAndConsonants getCategory(Character c) {
        if(VOWEL.chars.contains(c))
            return VOWEL;
        if(SOMETIMES_A_VOWEL.chars.contains(c))
            return SOMETIMES_A_VOWEL;
        return CONSONANT;
    }

    public static void main(String[] args) {
        Random rand = new Random(47);
        for (int i = 0; i < 100; i++) {
            int c = rand.nextInt(26) + 'a';
            printnb((char) c + ", " + c + ": ");
            print(E05_VowelsAndConsonants.getCategory((char) c).toString());
        }
    }
}
